package com.J.Plane;

import javax.microedition.khronos.opengles.GL10;

/**
 * This guy controls camera which can be local or global. 
 */
public class Camera extends Frustum {
	
	private Vector3 mEye;
	private Vector3 mAt;
	private Vector3 mUp;
	
	private boolean mNeedUpdateView;
	private Matrix44 mCachedViewMatrix;
	
	public Camera() {
		mEye = new Vector3(0,0,-500);
		mAt = new Vector3(0,0,0);
		mUp = new Vector3(0,1,0);
		
		mCachedViewMatrix = new Matrix44();
		mNeedUpdateView = true;
	}
	
	
	public Camera eye(float x, float y, float z) {
		mEye.set(x, y, z);
		needUpdateView();
		return this;
	}
	public final Vector3 eye() {
		return mEye;
	}
	public Camera at(float x, float y, float z) {
		mAt.set(x, y, z);
		needUpdateView();
		return this;
	}
	public final Vector3 at() {
		return mAt;
	}
	public Camera up(float x, float y, float z) {
		mUp.set(x, y, z);
		needUpdateView();
		return this;
	}
	public Vector3 up() {
		return mUp;
	}
	

	private void needUpdateView() {
		mNeedUpdateView = true;
	}
	
	
	public void setViewToWorldMatrix(GL10 gl) {
		if(mNeedUpdateView) {
			updateViewMatrix();
		}
		
		gl.glMatrixMode(GL10.GL_MODELVIEW);
		gl.glMultMatrixf(mCachedViewMatrix.getFloatBuffer());
	}
	
	private void updateViewMatrix() {
		if(mNeedUpdateView) {
		}
	}
}


